
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>

int main() {
    int num = 10;
    pid_t pid = fork();
    if (pid < 0) {
        perror("fork failed");
        return 1;
    } else if (pid == 0) {
        // 子进程
        
        printf("Child process: num = %d, address = %p\n", num, &num);
        printf("Child process: num = %d, address = %p\n", num, &num);
        printf("Child process: num = %d, address = %p\n", num, &num);
        printf("Child process: num = %d, address = %p\n", num, &num);
        printf("Child process: num = %d, address = %p\n", num, &num);
    }
     else {
        // 父进程
        sleep(1); // 确保子进程先执行写操作
        printf("Parent process: num = %d, address = %p\n", num, &num);
        printf("Parent process: num = %d, address = %p\n", num, &num);
        printf("Parent process: num = %d, address = %p\n", num, &num);
        printf("Parent process: num = %d, address = %p\n", num, &num);
    }
    return 0;
}
